import { Modal, Spin } from 'antd';
import React from 'react';
import { isEmpty, omit } from 'lodash';

class ModalComp extends React.Component {

  render() {
    const { action, loading } = this.props;
    const moreProps = {
      ...omit(this.props, ['action', 'loading']),
    };
    if (!isEmpty(action)) {
      moreProps.footer = action;
    }

    return (
      <Modal
        visible={this.props.isShowDetail}
        confirmLoading={loading}
        keyboard={false}
        maskClosable={false}
        {...moreProps}
      >
        <Spin delay={300} spinning={loading}>
          {
            this.props.children
          }
        </Spin>
      </Modal>
    );
  }
}

ModalComp.defaultProps = {
  visible: false, // 是否显示
  loading: false, // 是否正在加载
  title: '',
  action: null, // 自定义操作按钮
  onOk: null, // 点击确认后的回调
  onCancel: null, // 点击取消后的回调
};

export default ModalComp;
